local RSNG = RSNG
local AceOO = AceLibrary("AceOO-2.0")
local C = RSNG.Classes

local StatusBarInfo = AceOO.Class(C.FilteredStatusBarInfo, C.ItooltipInfo)

function StatusBarInfo.prototype:GetDefaultText()
	return L["Count"]
end

function StatusBarInfo.prototype:GetDefaultTextFormat()
	return L["%d / %d"]
end

function StatusBarInfo.prototype:GetDefaultColor()
	return 1.0, 0.0, 0.0
end

function StatusBarInfo.prototype:GetCount()
	local value, count = 0, 0
	local fo = self.filterout
	for unit, name, class, group, dead, online in RSNG:ApplyFilter(self.filterin) do
		if fo:Filter(unit, name, class, group, dead, online) then
			value = value + 1
		end
		count = count + 1
	end
	return 0, count, value
end

function StatusBarInfo.prototype:init()
	self.filterin = C.ListFilter:new()
	self.filterout = C.ListFilter:new()
end

function StatusBarInfo.prototype:FilterSerialize(type, data)
	if type == "save" then
		local f = {}
		self.filterin:Serialize("save", f)
		data.fin = f
		f = {}
		self.filterout:Serialize("save", f)
		data.fout = f
	elseif type == "load" then
		local f = data.fin
		if f then
			self.filterin:Serialize("load", f)
		end
		f = data.fout
		if f then
			self.filterout:Serialize("load", f)
		end
	end
end

function StatusBarInfo.prototype:FilterGetOptionTable()
	local fin = self.filterin:GetOptionTable()
	local fout = self.filterout:GetOptionTable()
	fin.name = L["Inclusive Filter"]
	fin.order = 100
	fout.name = L["Exclusive Filter"]
	fout.order = 200
	return {
		name = L["Filters"],
		type = "group",
		args = {
			filterin = fin,
			filterout = fout,
		}
	}
end

RSNG:RegisterStatusBarInfo(L["Count Bar"], StatusBarInfo)
